﻿namespace MEF_Test.Bricks
{
    using System;
    using System.Windows;
    using System.Windows.Controls;

    using MEF_Test.Contracts;

    public class BrowserNodeTemplateSelector : DataTemplateSelector
    {
        /// <summary>
        /// Returns a <see cref="T:System.Windows.DataTemplate"/> based on its TemplateProvider.
        /// </summary>
        /// <param name="item">The data object for which to select the template.</param>
        /// <param name="container">The data-bound object.</param>
        /// <returns>
        /// Returns a <see cref="T:System.Windows.DataTemplate"/>.
        /// </returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {            
            // If Template is not set : use a default template.
            if (((IBrowserNodeViewModel)item).Template == null)
            {
                return null;
                //FIXME : What should a default template look like ?
                //var resourceDictionary = new ResourceDictionary { Source = new Uri("/MEF-Test.Bricks;component/MediaBrowser/DefaultTemplates.xaml", UriKind.Relative) };
                //return (DataTemplate)resourceDictionary["BrowserNodeBaseTemplate"];
            }

            return ((IBrowserNodeViewModel)item).Template;                       
        }
    }
}
